<template>
  <label class="checkbox-wrap">
    <!-- <input
      type="checkbox"
      v-model="model"
    /> -->
<!--    <input type="checkbox" v-model="model" @change="onChange" />-->
    <input type="checkbox" v-model="model" @change="onChange" />
    <i class="check-icon">✓</i>
    <slot></slot>
  </label>
</template>


<script>
// import { reactive, toRefs, computed } from "vue";
// import { ref } from "vue";
// // import MyCheckbox from myCheckboxVue
// import myCheckboxVue from "./my-checkbox.vue";

import { getCurrentInstance } from 'vue';
export function useCheckbox(props) {
  const { proxy } = getCurrentInstance()
  const model = computed({
    get() {
      return props.modelValue;
    },
    set(val) {
      proxy.emit("update:modelValue", val);
    },
  });

  const onChange = () => {
    proxy.emit('change', model.value);
  }

  return {
    model,
    onChange
  }
}

// export default {
//   props: {
//     modelValue: {
//       type: [Boolean, Number, String],
//       default: () => undefined,
//     },
//   },
//    emits: ['change'],
//   setup(props, { emit }) {
//     const model = computed({
//       get() {
//         return props.modelValue;
//       },
//       set(val) {
//         emit("update:modelValue", val);
//       },
//     });

//    const onChange = () => {
//       emit('change', model.value);
//     }

//     return {
//       model,onChange
//     };
//   },
// };
</script>

<style lang="less" scoped>
@color: #333;
@activeColor: #409eff;
.checkbox-wrap {
  margin-right: 15px;
  font-size: 14px;
  user-select: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  .check-icon {
    margin-right: 5px;
    font-size: 14px;
    font-style: normal;
    display: inline-block;
    width: 14px;
    height: 14px;
    text-align: center;
    line-height: 14px;
    color: #fff;
    border: 1px solid @color;
    transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  }
  input[type="checkbox"] {
    display: none;
  }
  input[type="checkbox"]:checked + .check-icon {
    background-color: @activeColor;
    border-color: @activeColor;
  }
  &.is-checked-text {
    color: @activeColor;
  }
}
</style>
